var bmap = require("../../libs/bmap-wx.min.js");
// const util = require('../../../../util/util.js')
var wxMarkerData = [];
Page({
  data: {
    arrayCurrentCarInfo: [],
    markers: [],
    latitude: "40.049191",
    longitude: "116.280190",
    showV: false,
    butt: "add",
  },
  showPopup() {
    // if ((this.data.showV = true)) {
    //   this.setData({ butt: "clear" });
    // } else {
    //   this.setData({ butt: "add" });
    // }

    this.setData({ showV: !this.data.showV });
  },

  onLoad: function () {
    var BMap = new bmap.BMapWX({
      ak: "tEmJ2Qdq06YVa1mZDxrz509Cquqom80H",
    });

    // var fail = function (data) {
    //   console.log('失败')
    //   console.log(data)
    // };
    // var success = function (data) {
    //   console.log('成功')
    //   wxMarkerData = data.wxMarkerData;
    //   that.setData({
    //     markers: wxMarkerData
    //   });
    //   that.setData({
    //     latitude: wxMarkerData[0].latitude
    //   });
    //   that.setData({
    //     longitude: wxMarkerData[0].longitude
    //   });
    // }
    // BMap.geocoding({
    //   address: '北京市海淀区上地十街10号',
    //   fail: fail,
    //   success: success,
    //   iconPath: '../../img/marker_red.png',
    //   iconTapPath: '../../img/marker_red.png'
    // });

    this.getCurrentCarInfo();
  },
  // 获取信息
  getCurrentCarInfo() {
    var that = this;
    wx.request({
      url:
        "https://www.ejingyou.cn/ServerHuanwei/CompanyapiBDEapi/Vehicle/GetCarListCurrentVehicle",
      data: {
        CLIENTNO: "00000",
        CARSTATUS: "1",
        CARTYPE: "",
        CARGROUP: "",
        LICENSEPLATE: "",
      },
      header: {
        "content-type": "application/json", // 默认值
      },
      success: (res) => {
        var markerInfo = [];

        res.data.forEach((element) => {
          var dataC = {
            title: element.LICENSEPLATE,
            longitude: element.LNG,
            latitude: element.LAT,
            height: 50,
            width: 50,
          };
          var strImage = "";
          switch (element.CARTYPE) {
            case "除雪车":
              strImage = "1";
              break;
            case "高压清洗车":
              strImage = "2";
              break;
            case "机扫车":
              strImage = "3";
              break;
            case "洒水车":
              strImage = "4";
              break;
            case "吸尘车":
              strImage = "5";
              break;
            case "洗路车":
              strImage = "6";
              break;
            case "小型机扫车":
              strImage = "7";
              break;
            default:
              strImage = "8";
              break;
          }
          dataC.iconPath =
            "../../images/markerVehicle/" + strImage + element.STATUS + "B.png";
          markerInfo.push(dataC);
          //   // {"CompanyName":null,"IsSetupWater":"0","WATER":null,"ALLSUM":270,"VID":1306,"CLIENTNO":"000000914",
          //   // "LNG":117.34573905300117,"LAT":39.09233708397953,"GPSTIME":"2021-07-22T08:00:22","SPEED":1.5,"DIRECTION":"西",
          //   // "STATUS":6,"LOCATION":"天津市东丽区G103(津塘公路)","LICENSEPLATE":"华明津C607D5","CARDNO":"14702223984",
          //   // "CARTYPE":"高压清洗车","CLIENTNAME":"博德尔机扫队","VISIBLE":0,"LNGOFFSET":0,"LATOFFSET":0,"TEMPERATURERT":1,
          //   // "OIL":0,"IsSetupOil":0,"LOCKSTATUS":1,"VIDEO":0,"CURRENTNUM":6,"ISONLINE":0,"LOCK":0},{
        });
        that.setData({
          markers: markerInfo,
        });
        that.setData({
          latitude: markerInfo[0].latitude,
        });
        that.setData({
          longitude: markerInfo[0].longitude,
        });
      },
    });
  },
});
